//
//  InterstitialVC.m
//  CJModileAdDemo
//
//  Created by CJ on 2022/3/7.
//

#import "InterstitialVC.h"
#import <CJMobileAd/CJMobileAd.h>
#import <BUAdSDK/BUAdSDK.h>
#import "CustomShowView.h"

@interface InterstitialVC ()<BUNativeExpressFullscreenVideoAdDelegate>

@property (nonatomic, strong) BUNativeExpressFullscreenVideoAd *byte_interstitialAd;

@end

@implementation InterstitialVC

@synthesize customView = _customView;

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
}

- (void)dealloc
{
    NSLog(@"事件:%s", __FUNCTION__);
}

- (void)loadAdData {
    BUNativeExpressFullscreenVideoAd *byteInterstitialAd = [[BUNativeExpressFullscreenVideoAd alloc] initWithSlotID:@"103566413"];
    byteInterstitialAd.delegate = self;
    [byteInterstitialAd loadAdData];
    self.byte_interstitialAd = byteInterstitialAd;
}

- (void)setupUI {
    self.title = @"InterstitialAd";
    [self.view addSubview:self.customView];
    self.customView.frame = CGRectMake(0, 100, 200, 200);
    self.customView.center = self.view.center;
}

- (void)handleEvent:(NSInteger)eve {
    if (eve == 0) {
        NSLog(@"事件:%s", __FUNCTION__);
        [self loadAdData];
        return;
    }
}


- (CustomShowView *)customView {
    if (!_customView) {
        _customView = [[CustomShowView alloc] init];
        __weak InterstitialVC *weakSelf = self;
        _customView.event = ^(NSInteger eve) {
            [weakSelf handleEvent:eve];
        };
    }
    return _customView;
}

#pragma mark BUNativeExpressFullscreenVideoAdDelegate
- (void)nativeExpressFullscreenVideoAdDidLoad:(BUNativeExpressFullscreenVideoAd *)fullscreenVideoAd {
    NSLog(@"事件:%s", __FUNCTION__);
    [fullscreenVideoAd showAdFromRootViewController:self];
}

- (void)nativeExpressFullscreenVideoAdDidVisible:(BUNativeExpressFullscreenVideoAd *)fullscreenVideoAd {
    NSLog(@"事件:%s", __FUNCTION__);
}

- (void)nativeExpressFullscreenVideoAd:(BUNativeExpressFullscreenVideoAd *)fullscreenVideoAd didFailWithError:(NSError *_Nullable)error {
    NSLog(@"事件:%s", __FUNCTION__);
}

- (void)nativeExpressFullscreenVideoAdViewRenderFail:(BUNativeExpressFullscreenVideoAd *)rewardedVideoAd error:(NSError *_Nullable)error {
    NSLog(@"事件:%s", __FUNCTION__);
}

- (void)nativeExpressFullscreenVideoAdDidClick:(BUNativeExpressFullscreenVideoAd *)fullscreenVideoAd {
    NSLog(@"事件:%s", __FUNCTION__);
}

- (void)nativeExpressFullscreenVideoAdDidClose:(BUNativeExpressFullscreenVideoAd *)fullscreenVideoAd {
    NSLog(@"事件:%s", __FUNCTION__);
}

@end
